<?php
	require_once "include/User.php";
	require_once "include/Article.php";
	require_once "include/Template.php";
	require_once "include/backend/ArticlesDb.php";
	
	 // creating template and setting the possibly logged in user
	$page = new Template();
	session_start();
	$page->setUser($_SESSION['user']);
	
	$pageNr = $_GET['page'];
	if (!is_numeric($pageNr))
		$pageNr = 0;
	$offset = $pageNr*8;
	
	// getting articles from the database
	$articles = new ArticlesDb();
	$nrArts = $articles->getNrArticles();
	$result = $articles->get(8, null, $offset);
	$result = $articles->result2array($result);
	
	$html = "";
	for ($i=0; $i < ($nrArts/8); $i++)
		$html .= "<a href=\"browse.php?page=".$i."\">".$i."</a> ";
	$page->addContent($html);
	
	// adding them to the template
	for ($i = 0; $i < count($result); $i++) {
		$article = new Article($result[$i], true);
		$page->addContent($article->getHTML());
	}
	
	$page->addContent("<hr class=\"clearer\">");
	$page->addContent($html);
	
	// outputting the html
	echo $page->getHTML();
?>
